"use strict";
const fs = require("fs");
const cliSelect = require("cli-select");

const getAction = (question, values) => {
    console.log(question);
    const valueRenderer = (answer, selected) => answer;

    return new Promise((resolve) => {
        cliSelect({ values, valueRenderer }).then(({ value }) => resolve(value));
    });
};

const updateRunEnv = async () => {
    let runEnvOptions = ["dev", "testing", "production"];
    const runEnv = await getAction("请选择运行环境: ", runEnvOptions);
    console.log(runEnv);
    fs.writeFileSync("./publish/run.env.json", `{ "current": "${runEnv}" }`, "utf8");
};

updateRunEnv();

module.exports = {
    updateRunEnv,
};
